clear

********************************************************************************

import excel "./data/KimWrightTermPremium.xlsx", sheet("Daily") firstrow
 gen date = mdy(MONTH,DATE,YEAR)
format date %td
sort date

keep date THREEFY0200B THREEFY0500B THREEFY1000B THREEFYTP0200B THREEFYTP0500B THREEFYTP1000B 
rename THREEFY0200B yield2y
rename THREEFY0500B yield5y 
rename THREEFY1000B yield10y 
rename THREEFYTP0200B tp_2y
rename THREEFYTP0500B tp_5y
rename THREEFYTP1000B tp_10y

gen exp_2y = yield2y - tp_2y
gen exp_5y = yield5y - tp_5y
gen exp_10y = yield10y - tp_10y


* Calculate Asset Price Change
egen time = group(date)
sort time
tsset time

* fill missing values with previous value before calculating change in asset prices
replace yield2y = L.yield2y if yield2y == .
replace yield5y = L.yield5y if yield5y == .
replace yield10y = L.yield10y if yield10y == .

replace tp_2y = L.tp_2y if tp_2y == .
replace tp_5y = L.tp_5y if tp_5y == .
replace tp_10y = L.tp_10y if tp_10y == .

replace exp_2y = L.exp_2y if exp_2y == .
replace exp_5y = L.exp_5y if exp_5y == .
replace exp_10y = L.exp_10y if exp_10y == .


forvalues i=0/1 {
	
	gen two_yr`i'  = .
	gen five_yr`i' = .
	gen ten_yr`i'  = .
	
	gen tp_two_yr`i'  = .
	gen tp_five_yr`i'  = .
	gen tp_ten_yr`i'  = .

	gen exp_two_yr`i'  = .
	gen exp_five_yr`i'  = .
	gen exp_ten_yr`i'  = .
	 
	replace two_yr`i'  = (f`i'.yield2y) - (l.yield2y) 
	replace five_yr`i' = (f`i'.yield5y) - (l.yield5y) 
	replace ten_yr`i'  = (f`i'.yield10y) - (l.yield10y) 
	
	replace tp_two_yr`i'  = (f`i'.tp_2y) - (l.tp_2y) 
	replace tp_five_yr`i'  = (f`i'.tp_5y) - (l.tp_5y) 
	replace tp_ten_yr`i'  = (f`i'.tp_10y) - (l.tp_10y)
	
	replace exp_two_yr`i'  = (f`i'.exp_2y) - (l.exp_2y) 
	replace exp_five_yr`i'  = (f`i'.exp_5y) - (l.exp_5y) 
	replace exp_ten_yr`i'  = (f`i'.exp_10y) - (l.exp_10y) 

	}
	

rename two_yr0 yield2y_1day
rename two_yr1 yield2y_2day
rename five_yr0 yield5y_1day
rename five_yr1 yield5y_2day
rename ten_yr0 yield10y_1day
rename ten_yr1 yield10y_2day

rename tp_two_yr0 tp2y_1day
rename tp_two_yr1 tp2y_2day
rename tp_five_yr0 tp5y_1day
rename tp_five_yr1 tp5y_2day
rename tp_ten_yr0 tp10y_1day
rename tp_ten_yr1 tp10y_2day

rename exp_two_yr0 exp2y_1day 
rename exp_two_yr1 exp2y_2day
rename exp_five_yr0 exp5y_1day 
rename exp_five_yr1 exp5y_2day
rename exp_ten_yr0 exp10y_1day 
rename exp_ten_yr1 exp10y_2day


* Merge MP Data
merge m:1 date using "./data/mp_data.dta"
keep if _merge == 3
drop _merge


* Standardize Asset Changes
rename exp2y_2day exp2y_unscl
rename exp10y_2day exp10y_unscl
rename tp2y_2day tp2y_unscl
rename tp10y_2day tp10y_unscl
egen exp2y_std = sd(exp2y_unscl)
egen exp10y_std = sd(exp10y_unscl)
egen tp2y_std = sd(tp2y_unscl)
egen tp10y_std = sd(tp10y_unscl)
sort date
gen exp2y_2day = exp2y_unscl/exp2y_std
gen exp10y_2day = exp10y_unscl/exp10y_std
gen tp2y_2day = tp2y_unscl/tp2y_std
gen tp10y_2day = tp10y_unscl/tp10y_std

label var yield2y_1day "2 Year Yield"
label var yield2y_2day "2 Year Yield"
label var yield5y_1day "5 Year Yield"
label var yield5y_2day "5 Year Yield"
label var yield10y_1day "10 Year Yield"
label var yield10y_2day "10 Year Yield"

label var tp2y_1day "2 Year Term Prm"
label var tp2y_2day "2 Year Term Prm"
label var tp5y_1day "5 Year Term Prm"
label var tp5y_2day "5 Year Term Prm"
label var tp10y_1day "10 Year Term Prm"
label var tp10y_2day "10 Year Term Prm"

label var exp2y_1day "2 Year Exp Comp"
label var exp2y_2day "2 Year Exp Comp"
label var exp5y_1day "5 Year Exp Comp"
label var exp5y_2day "5 Year Exp Comp"
label var exp10y_1day "10 Year Exp Comp"
label var exp10y_2day "10 Year Exp Comp"


* Start sample in 1995
keep if date >= td(01jan1995)

********************************************************************************
*** Response of US bond term premia to monetary policy shocks ***
reg tp2y_2day mps_2day mpu_2day,  vce(cluster date)
outreg2 using "tables\tableA6_c.xml", replace se bdec(3) label
reg tp10y_2day mps_2day mpu_2day,  vce(cluster date)
outreg2 using "tables\tableA6_c.xml", append se bdec(3) label

********************************************************************************
